$import( "SmitearWebGL.Objects.Parser.Collada.DaeEntity" );
$import( "SmitearWebGL.Objects.Parser.Collada.DaeBindMaterial" );

SmitearWebGL.Objects.Parser.Collada.DaeInstanceGeometry = SmitearWebGL.Objects.Parser.Collada.DaeEntity.extend(
{
	/******** constructor ********/

	init : function( document, node )
	{
		this.url = "";
		this.bindMaterial = null;

		this._super( document, node );
		this._registClass( "SmitearWebGL.Objects.Parser.Collada.DaeInstanceGeometry" );
	}
	,
	destroy : function()
	{
		this._super();

		if(this.bindMaterial)
		{
			this.bindMaterial.destroy();
			this.bindMaterial = null;
		}
	}
	,
	findBindVertexInput : function( materialId, semantic )
	{
		var material = this.bindMaterial.getInstanceMaterialBySymbol( materialId );

		if(material)
		{
			return material.findBindVertexInput( semantic );
		}

		return null;
	}
	,
	read : function( node )
	{
		this._super( node );

		this.url = this.getAttribute( node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_URL_ATTRIBUTE );

		var children = node.childNodes;

		for( var i = 0; i < children.length; i++ )
		{
			var child = children[i];

			switch( child.localName )
			{
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_BINDMATERIAL_ELEMENT:
					this.bindMaterial = new SmitearWebGL.Objects.Parser.Collada.DaeBindMaterial(this.document, child);
					break;

				default:
					break;
			}
		}
	}
}
);